package com.uinnova.springboot.web.interceptor;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/*
*@author 王刚
*@date 2019-01-09 09:27
*测试拦截器：
*           先访问/jail/interceptor/intercepted，被拦截并重定向到/jail/interceptor/login,在这里session中存入数据，所以再次访问被拦截的/jail/interceptor/intercepted不会被拦截
*
*/
@Controller
public class InterceptorController {


    /*
    *重定向到login页面
    * 往session里面放数据
    */
    @RequestMapping(value = "/jail/interceptor/login")
    public String toLogin(HttpServletRequest request){
        HttpSession session = request.getSession();
        session.setAttribute("testinterceptor","测试interceptor的session");
        return "/index.html";
    }

    /*
    *测试被拦截的路径
    */
    @RequestMapping(value = "/jail/interceptor/intercepted")
    public String toView(){
        return "/view.html";
    }
}
